home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / quicktime / all java / quicktime for java / musicmixer / src / mixer / display / soundtrackdisplay.java < prev   
Encoding:
Java Source  |  2000-06-23  |  4.3 KB  |  135 lines

  1. /*
  2.  * QuickTime for Java SDK Sample Code
  3.  
  4.    Usage subject to restrictions in SDK License Agreement
  5.  * Copyright: © 1996-1999 Apple Computer, Inc.
  6.  
  7.  */
  8. package mixer.display;
  9.  
  10. import java.awt.*;
  11. import java.awt.event.*;
  12. import javax.swing.*;
  13. import javax.swing.event.*;
  14.  
  15. import quicktime.*;
  16. import quicktime.app.audio.*;
  17. import quicktime.std.movies.media.*;
  18.  
  19. import mixer.mc.*;
  20.  
  21. /** This is our class to display the controls for a typical sound (or music) track
  22.  *  in a movie.  It permits all controls because all of the controls are valid
  23.  *  settings for a sound track.
  24.  */
  25. public class SoundTrackDisplay extends MasterDisplay {
  26.     private boolean soloed;  // true = another channel has turned this one off
  27.     private SoloableChannels parent;
  28.     
  29.     /** The constructor needs to know which SoloableChannel object made it (for the solo
  30.      *  stuff) and which MixerComponents it's making the display for.
  31.      * @param par the SoloableChannels object that created this object
  32.      * @param media the MixerComponents object to make the display for
  33.      */
  34.     public SoundTrackDisplay (SoloableChannels par, MixerComponents media) throws QTException {
  35.         this (par, media, true, true, true, true);        
  36.     }
  37.     
  38.     protected SoundTrackDisplay (SoloableChannels par, MixerComponents media, boolean mute, boolean solo, boolean balance, boolean volume) throws QTException {
  39.         super (media, mute, solo, balance, volume);
  40.  
  41.         parent = par;
  42.         soloed = false;
  43.     }
  44.  
  45.     /* This method adds the action listener appropriate for SoundTrackDisplays to the
  46.      * solo button it gets as an argument.  Note that the code actually must call the
  47.      * SoloableChannels parent object to perform the solo operation.
  48.      */
  49.     void addSoloAction (JCheckBox b) {
  50.         b.addActionListener(new ActionListener() {
  51.             public void actionPerformed(ActionEvent e) {
  52.                 try {
  53.                     if (((JCheckBox) e.getSource()).isSelected()) {
  54.                         if (false == muteButton.isSelected())
  55.                             mixer.getMaster().setMuted(false);
  56.                         parent.setSolo(true);
  57.                     }
  58.                     else {
  59.                         if (false == soloed  && false == muteButton.isSelected())
  60.                             mixer.getMaster().setMuted(false);
  61.                         parent.setSolo(false);
  62.                     }
  63.                 }
  64.                 catch (QTException ex) {
  65.                     throw new QTRuntimeException (ex);
  66.                 }
  67.             }
  68.         });
  69.     }
  70.     
  71.     /* This method adds the ActionListener needed for mute buttons. */
  72.     void addMuteAction (JCheckBox b) {
  73.         try {
  74.             b.setSelected (mixer.getMaster().isMuted());
  75.             b.addActionListener(new ActionListener() {
  76.                 public void actionPerformed(ActionEvent e) {
  77.                     try {
  78.                         if (((JCheckBox) e.getSource()).isSelected())
  79.                             mixer.getMaster().setMuted(true);
  80.                         else
  81.                             if (false == soloed || true == soloButton.isSelected())
  82.                                 mixer.getMaster().setMuted(false);
  83.                     }
  84.                     catch (QTException ex) {
  85.                         throw new QTRuntimeException (ex);
  86.                     }
  87.                 }
  88.             });
  89.         } catch (QTException e) {
  90.             throw new QTRuntimeException (e);
  91.         }
  92.     }
  93.     
  94.     /* This method adds the ActionListener needed for balance sliders. */
  95.     void addBalanceAction (JSlider b) {
  96.         try {
  97.             b.setValue((int)(((ExtendedAudioSpec)mixer.getMaster()).getBalance() * 100.0F));
  98.             b.addChangeListener(new ChangeListener() {
  99.                 public void stateChanged(ChangeEvent e) {
  100.                     try {
  101.                         JSlider source = (JSlider) e.getSource();
  102.                         Integer tmp = new Integer(source.getValue());
  103.                         float p = tmp.floatValue();
  104.                         p = p / 100.0F;
  105.                         ((ExtendedAudioSpec) mixer.getMaster()).setBalance(p);
  106.                     }
  107.                     catch (QTException ex) {
  108.                         throw new QTRuntimeException (ex);
  109.                     }
  110.                 }
  111.             });
  112.         } catch (QTException e) {
  113.             throw new QTRuntimeException (e);
  114.         }
  115.     }
  116.  
  117.     /* This method is invoked by the SoloableChannels parent object whenever
  118.      * a channel (including this one) changes its solo state.  The argument is
  119.      * a count of the number of channels currently holding the solo state.
  120.      */
  121.     void doSolo(int count) throws QTException {
  122.         if (false == soloButton.isSelected()) { // this channel is not solo
  123.             if (count > 0) {                // another channel is solo
  124.                 mixer.getMaster().setMuted(true);
  125.                 soloed = true;
  126.             }
  127.             else {                          // no channels are solo
  128.                 if (false == muteButton.isSelected())  // this channel is not muted
  129.                     mixer.getMaster().setMuted(false);      // so let it play
  130.                 soloed = false;
  131.             }
  132.         }
  133.     }
  134. }
  135.